package net.wangds.web.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.Base64;

public final class UploadUtils {

    public static final String BASE64_KEY = ";base64,";
    public static final int BASE64_KEY_LENGTH = BASE64_KEY.length();

    /**
     * 从url格式字符串中获取文件内容.
     * @param content url格式字符串.
     * @return 文件内容.
     */
    public static byte[] readUrlContent(String content){

        byte[] res = new byte[0];
        if(StringUtils.isBlank(content)){
            return res;
        }

        int idx = content.indexOf(BASE64_KEY);
        if(idx>0){
            String b64str = content.substring(idx+BASE64_KEY_LENGTH);
            res = Base64.getDecoder().decode(b64str);
        }
        return res;
    }

}
